editor.once('load', () => {
    editor.method('wasm:load', (modules, urlPrefix, doneCallback) => {
        if (typeof modules === 'undefined' || modules.length === 0) {
            // caller may depend on callback behavior being async
            setTimeout(doneCallback);
        } else {
            let remaining = modules.length;
            const moduleLoaded = () => {
                if (--remaining === 0) {
                    doneCallback();
                }
            };

            modules.forEach((m) => {
                pc.WasmModule.setConfig(m.moduleName, {
                    glueUrl: urlPrefix + m.glueUrl,
                    wasmUrl: urlPrefix + m.wasmUrl,
                    fallbackUrl: urlPrefix + m.fallbackUrl
                });

                if (!m.hasOwnProperty('preload') || m.preload) {
                    if (m.moduleName === 'BASIS') {
                        // preload basis transcoder
                        pc.basisInitialize();
                        moduleLoaded();
                    } else if (m.moduleName === 'DracoDecoderModule') {
                        // preload draco decoder
                        if (pc.dracoInitialize) {
                            // 1.63 onwards
                            pc.dracoInitialize();
                            moduleLoaded();
                        } else {
                            // 1.62 and earlier
                            pc.WasmModule.getInstance(m.moduleName, () => {
                                moduleLoaded();
                            });
                        }
                    } else {
                        // load remaining modules in global scope
                        pc.WasmModule.getInstance(m.moduleName, () => {
                            moduleLoaded();
                        });
                    }
                } else {
                    moduleLoaded();
                }
            });
        }
    });
});
